package com.example.robotwatcher;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainInterface extends AppCompatActivity {


    private FirstFragment firstFragment = new FirstFragment();
    private MainFragment  mainFragment   = new MainFragment();
    private MineFragment mineFragment = new MineFragment();
    private FragmentManager manager;
    private FragmentTransaction transaction;
    private Fragment currentFragment;
    private Intent intent;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_interface);

        Button mine = findViewById(R.id.main_btn_Mine);
        mine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                    FragmentHideShow(mineFragment);


            }
        });

        Button main = findViewById(R.id.main_btn_Main);
        main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentHideShow(mainFragment);

            }
        });

        Button first = findViewById(R.id.main_btn_First);
        first.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentHideShow(firstFragment);

            }
        });

        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
        transaction.show(firstFragment);
        transaction.show(mainFragment);
        transaction.show(mineFragment);
        transaction.commit();
        currentFragment = firstFragment;
        FragmentHideShow(firstFragment);

    }


    private  void FragmentHideShow(Fragment fg){
        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
        if (!fg.isAdded()){
            transaction.hide(currentFragment);
            transaction.add(R.id.frameLayout,fg);
        }else{
            transaction.hide(currentFragment);
            transaction.show(fg);
        }
        currentFragment = fg;
        transaction.commit();
    }

}